< previous page page_114 next page >

Page 114
class modules for serving objects into memory only when a client object invokes a method in the serving object's class module. Therefore, having a small set of logically related methods per class module means that the Visual Basic compiler only loads such modules into memory when one of those methods is invoked. A small set of methods would likely consist of three to five public methods and five to seven private methods. Do not overuse property methods; this can be an indicator of a poor design that might unnecessarily break encapsulation.
Finally, you should be aware of memory considerations in constructing components in Visual Basic. Because every in-process component has a chance of using the same memory location of other like components or executables, you must manipulate the component's base address to make it distinctive. This is important for distributed architectures in environments such as companies and university computer labs where multiple clients access a set of components on a given server. If this characterizes your situation, you need to rebase the component. See Setting Base Addresses for In-Process Components in Visual Basic's Books Online for more information.
New Term: An in-process component is one that is realized in the form of a DLL or OCX file and runs in the address space of the client. ActiveX components can be designed as in-process.
Planning for Object Reuse Early in the Visual Basic Project
Planning for any form of reuse is very difficult and initially slows down your projects. However, one excellent benefit of object-oriented programming is that you can systematically take advantage of the work of predecessors. The best way to achieve reuse is through
Well-defined class interfaces in which each interface has only a few, well-encapsulated public methods
Elaboration of abstractions from unambiguous terms and concepts in the domain
Uncomplicated class inheritance relationships or delegation
Well-documented use cases that can be reused
Commitment from fellow team members to practice good object-oriented programming
Planning reuse also requires the investigation of repetitive code patterns, among other project artifacts. For instance, if you notice that each of several methods you are using has code for loading information into a list box, you might need a commonly shared class responsible for loading information into a list box.

 
< previous page page_114 next page >

If you like this book, buy it!